package com.zj.利率;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

public class 先息后本 {

    public static void main(String[] args) {

        int total = 100000;
        float rate = 3.6f / 100;
        int year = 1;
        float moneyPerMonth = total * rate * year / (year * 12);
        List<Float> res = new ArrayList<>();
        List<Float> resFuli = new ArrayList<>();

        IntStream.range(30, 50).forEach(i -> {
            float rate1 = i / 1000.0F / 12;
            float res2 = 0;
            float res2Fuli = 0;
            System.out.println(rate1);
            for (int j = 0; j < year * 12; j++) {
                res2 += getProfit(moneyPerMonth, rate1, j);
                res2Fuli += getProfitWithFuli(moneyPerMonth, rate1, j);

            }
            res.add(res2 + total);
            resFuli.add(res2Fuli + total);

        });
        System.out.println(res);
        System.out.println(resFuli);


    }

    public static float getProfit(float benjin, float rate, int n) {
        return benjin * (1 + rate * n);
    }

    public static float getProfitWithFuli(float benjin, float rate, int n) {
        float res = benjin;
        for (int i = 0; i < n; i++) {
            res *= (1 + rate);
        }
        return res;
    }


}
